package com.lakeworks.web.controller.core;

import com.lakeworks.common.domain.channel.*;
import com.lakeworks.common.domain.channel.ticket.BarcodeVo;
import com.lakeworks.common.domain.channel.ticket.TicketAdvance;
import com.lakeworks.common.domain.channel.ticket.TicketFactory;
import com.lakeworks.common.domain.ticket.TktClaims;
import com.lakeworks.common.domain.ticket.TktClaimsRecord;
import com.lakeworks.common.domain.ticket.TktReclaim;
import com.lakeworks.service.IThirdChannelService;
import com.lakeworks.service.ITicketChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Size;
import java.util.List;

/**
 * @Author: Auxps
 * @Date: 2023/3/9
 * Description:
 * <p>
 * 三方渠道调用接口
 * 统一验证注解中的message 暂时 ChannelErrorEnum.getErrcode
 */
@RestController
@RequestMapping("/channel")
@Validated
public class ThirdChannelController {

    @Autowired
    private IThirdChannelService thirdChannelService;

    @Autowired
    private ITicketChannelService ticketChannelService;

    /**
     * 入厂单导入
     */
    @PostMapping("/pickup/{pickupNo}")
    public ResponseEntity pickupImport(@Size(min = 9,message = "40114") @PathVariable String pickupNo, @Valid @RequestBody PickupImport pickupImport) {
        return thirdChannelService.pickupImport(pickupNo, pickupImport);
    }

    /**
     * 入厂单修改（暂时只能修改运单号、预计到厂时间）
     * 传入的字段 均无需做非空判断
     */
    @PatchMapping("/pickup/{pickupNo}")
    public ResponseEntity pickupUpdate(@PathVariable String pickupNo, @Valid @RequestBody ExpressAlter expressAlter) {
        return thirdChannelService.pickupUpdate(pickupNo, expressAlter);
    }


    /**
     * 入厂单添加商品
     */
    @PostMapping("/pickup/{pickupNo}/merchandises")
    public ResponseEntity addMerchandises(@PathVariable String pickupNo, @RequestBody List<MerchandiseItem> merchandises) {
        return thirdChannelService.addMerchandises(pickupNo, merchandises);
    }


    /**
     * 入厂单修改商品
     */
    @PatchMapping("/pickup/{pickupNo}/merchandises")
    public ResponseEntity updateMerchandises(@PathVariable String pickupNo, @RequestBody String code) {
        return thirdChannelService.updateMerchandises(pickupNo, code);
    }

    /**
     * 出厂单修改产品
     */
    @PatchMapping("/shipment/{shipmentNo}/products")
    public ResponseEntity updateProducts(@PathVariable String shipmentNo, @RequestBody List<String> bracodes) {
        return thirdChannelService.updateProducts(shipmentNo, bracodes);
    }


    /**
     * 入厂单删除
     */
    @DeleteMapping("/pickup/{pickupNo}")
    public ResponseEntity deleteCancel(@PathVariable String pickupNo) {
        return thirdChannelService.deletePickup(pickupNo);
    }

    /**
     * 入厂单取消
     */
    @PutMapping("/pickup/{pickupNo}")
    public ResponseEntity pickupCancel(@PathVariable String pickupNo) {
        return thirdChannelService.pickupCancel(pickupNo);
    }




    /**
     * 出厂单导入
     */
    @PostMapping("/shipment/{shipmentNo}")
    public ResponseEntity syncShipment(@Size(min = 9, message = "40214") @PathVariable String shipmentNo, @Valid @RequestBody ShipmentImport shipmentImport) {
        return thirdChannelService.syncShipment(shipmentNo, shipmentImport);
    }

    /**
     * 下发物流信息
     */
    @PostMapping("/shipment/{shipmentNo}/express")
    public ResponseEntity express(@PathVariable("shipmentNo") String shipmentNo, @Valid @RequestBody ExpressInfo expressInfo) {
        return thirdChannelService.express(shipmentNo, expressInfo);
    }

    /**
     * 入厂单状态查询
     */
    @GetMapping("/pickup/{pickupNo}")
    public ResponseEntity getPickupInfo(@PathVariable String pickupNo) {
        return thirdChannelService.getPickupInfo(pickupNo);
    }

    /**
     * 产品状态查询
     */
    @GetMapping("/pickup/{pickupNo}/product/{barcode}")
    public ResponseEntity getProductInfo(@PathVariable String pickupNo, @PathVariable String barcode) {
        return thirdChannelService.getProductInfo(pickupNo, barcode);
    }

    /**
     * 出厂单状态查询
     */
    @GetMapping("/shipment/{shipmentNo}")
    public ResponseEntity geShipmentInfo(@PathVariable String shipmentNo) {
        return thirdChannelService.getShipmentInfo(shipmentNo);
    }


    /**
     * 添加系统产品信息
     */
    @PostMapping("/system/product/{code}")
    public ResponseEntity addSysProduct(@PathVariable String code, @Valid @RequestBody SysProductInfo sysProductInfo) {
        return thirdChannelService.addSysProduct(code, sysProductInfo);
    }

    /**
     * 修改系统产品信息
     */
    @PatchMapping("/system/product/{code}")
    public ResponseEntity updateSysProduct(@PathVariable String code, @Valid @RequestBody SysProductInfo sysProductInfo) {
        return thirdChannelService.updateSysProduct(code, sysProductInfo);
    }

    /**
     * 删除系统产品信息
     */
    @DeleteMapping("/system/product/{code}")
    public ResponseEntity deleteSysProduct(@PathVariable String code) {
        return thirdChannelService.deleteSysProduct(code);
    }

    /**
     * 修改产品绑定的衣物
     */
    @PatchMapping("/{barcode}/code")
    public ResponseEntity updateProductCode(@PathVariable String barcode, @RequestBody String code) {
        return thirdChannelService.updateProductCode(barcode,code);
    }


    /**
     * 添加系统瑕疵信息
     */
   /* @PostMapping("/system/flaw/{id}")
    public ResponseEntity addSysDefetive(@PathVariable Long id,@Valid SysDefectiveInfo sysDefectiveInfo){
        return thirdChannelService.addSysDefetive(id,sysDefectiveInfo);
    }*/

    /**
     * 修改系统瑕疵信息
     */
   /* @PatchMapping("/system/flaw/{id}")
    public ResponseEntity updateSysDefetive(@PathVariable Long id,@Valid SysDefectiveInfo sysDefectiveInfo){
        return thirdChannelService.updateSysDefetive(id,sysDefectiveInfo);
    }*/

    /**
     * 删除系统瑕疵信息
     */
    /*@DeleteMapping("/system/flaw/{id}")
    public ResponseEntity deleteSysDefetive(@PathVariable Long id){
        return thirdChannelService.deleteSysDefetive(id);
    }*/

    /**
     *获取平台工单决定选项
     * */
    /*@PostMapping("/ticket/option")
    public AjaxResult ticketOptions(@RequestBody TicketFeedbackFactory ticketFeedbackFactory){
        return tktTicketService.ticketOptions(ticketFeedbackFactory);
    }*/


    /**
     * 平台添加工单
     */
    @PostMapping("/ticket")
    public ResponseEntity addPlatform(@RequestBody @Valid TicketFactory ticketFactory) {
        return ticketChannelService.addPlatform(ticketFactory);
    }


    /**
     * 平台修改工单
     */
    @PostMapping("/operate")
    public ResponseEntity advanceTicket(@RequestBody TicketAdvance ticketAdvance) {
        return ticketChannelService.advanceTicket(ticketAdvance);
    }

    /**
     * 放开订单
     */
    @PostMapping("/{orderNo}/hold")
    public ResponseEntity holdOrder(@PathVariable("orderNo") String orderNo) {
        return thirdChannelService.holdOrder(orderNo);
    }


    /**
     * 下发赔偿单
     */
    @PostMapping("/ticket/claims")
    public ResponseEntity addClaims(@RequestBody @Valid TktClaims tktClaims){
        return ticketChannelService.addClaims(tktClaims);
    }

    /**
     * 修改赔偿单
     * */
    @PatchMapping("/ticket/claims")
    public ResponseEntity updateClaims(@RequestBody TktClaims tktClaims){return  ticketChannelService.updateClaims(tktClaims);}

    /**
     * 下发回收单
     */
    @PostMapping("/ticket/recalaim")
    public ResponseEntity addRecalaim(@RequestBody TktReclaim tktReclaim){
        return ticketChannelService.addRecalaim(tktReclaim);
    }


    /**
     * 修改洗涤方式
     * */
    @PostMapping("/products/washMode")
    ResponseEntity updateWashMode(@RequestBody List<BarcodeVo> barcodeVos){
        return ticketChannelService.updateWashMode(barcodeVos);
    }

    @PostMapping("/claims/arbitrament")
    ResponseEntity arbitrament(@RequestBody @Valid TktClaimsRecord tktClaimsRecord){
        return ticketChannelService.arbitrament(tktClaimsRecord);
    }


    @PostMapping("/express/status")
    public ResponseEntity expressStatus(@RequestBody @Valid ExpressVo expressVo){
        return thirdChannelService.expressStatus(expressVo);
    }

    @GetMapping("/product/post/{barcode}")
    public ResponseEntity statusByBarcode(@PathVariable String barcode) {
        return thirdChannelService.statusByBarcode(barcode);
    }



    @GetMapping("/shipment/barcodes")
    public ResponseEntity getBarcodes(QuaryVo quaryVo){
        return thirdChannelService.getBarcodes(quaryVo);
    }


}
